package com.woniuxy.orderassembly.controller;

import com.alipay.api.AlipayApiException;
import com.woniuxy.orderassembly.config.AliPayConfig;
import com.woniuxy.orderassembly.config.Alipay;
import com.woniuxy.orderassembly.pojo.AlipayPojo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Slf4j
@RestController
public class SynCallbackController {

    //同步回调的controller
    @Autowired
    private AliPayConfig aliPayConfig;

    @Resource
    private Alipay alipay;
    //outTradeNo：订单号  subject：订单名称  totalAmount:描述  description：描述可空
    //同步回调
    @PostMapping("/alipay")
    public String alipay (String outTradeNo, String subject,String totalAmount, String description) throws AlipayApiException {
        //获取订单id，支付宝接口调用必备
        AlipayPojo alipayPojo = new AlipayPojo();
        alipayPojo.setOut_trade_no(outTradeNo);
        alipayPojo.setSubject(subject);
        alipayPojo.setTotal_amount(totalAmount);
        alipayPojo.setDescription(description);
        System.out.println(alipayPojo);
        return alipay.pay(alipayPojo);//调用配置类pay方法
    }
}
